import itchat
from itchat.content import *
import requests

API = "http://www.tuling123.com/openapi/api"
API_KEY = "65c7e221e25f4812b32c9600a0ef10b7"

data = {
        "key": API_KEY,
        "info": "",
        "loc":"北京市中关村",
        "userid":""
    }

@itchat.msg_register(TEXT, isGroupChat=True)
def text_reply(msg):
    # print(msg)
    if msg.isAt:
        if msg.text[:1] == "@":
            print("收到的消息:%s" % msg.text[8:])
            data["info"] = msg.text[8:]
            data["userid"] = msg.FromUserName
            tuling = requests.post(API, data=data)
            result = tuling.json()["text"]
            print("回复的消息:%s" % result)

            msg.user.send(u'@%s\u2005%s' % (
                msg.actualNickName, result))
        else:
            msg.user.send(u'@%s\u2005亲,格式错误!请你先艾特我!' % (
                msg.actualNickName))



itchat.auto_login(True)
itchat.run(True)